package com.cx.mall.user.service.impl;

import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.cx.mall.common.model.user.UserReceiveAddress;
import com.cx.mall.user.mapper.UserReceiveAddressMapper;
import com.cx.mall.common.model.user.UserReceiveAddressDTO;
import com.cx.mall.user.service.IUserReceiveAddressService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * <p>
 * 用户收货地址表 服务实现类
 * </p>
 *
 * @author lyt
 * @since 2025-07-08
 */
@Service
public class UserReceiveAddressServiceImpl extends ServiceImpl<UserReceiveAddressMapper, UserReceiveAddress> implements IUserReceiveAddressService {
    @Override
    public List<UserReceiveAddressDTO> listByUserId(Long userId) {
        LambdaQueryChainWrapper<UserReceiveAddress> wrapper = new LambdaQueryChainWrapper<>(baseMapper);
        List<UserReceiveAddress> list = wrapper.eq(UserReceiveAddress::getUserId, userId).list();
        //将数据转换成DTO
        List<UserReceiveAddressDTO> dtos =
                JSON.parseArray(JSON.toJSONString(list), UserReceiveAddressDTO.class);
        return dtos;
    }
}
